<template>
	<view class="container">
		<view class="solid-bottom text-13 flex justify-between align-center padding bg-white">
			<view class="text-333 text-bold">
				商品
			</view>
			<view>{{productInfo.productName}}</view>

		</view>
		<!-- <view class="solid-bottom bg-white text-13 flex justify-between align-center padding">
			<view class="text-333 flex-sub text-bold">
				商品价格
			</view>
			<view class="flex-treble text-13 flex justify-between align-center">
				<input type="text" value="" class="text-13 f-grow1" placeholder="请填写商品单价" />
				<view class="color">
					元
				</view>
			</view>

		</view> -->
		<view class="solid-bottom bg-white text-13 flex justify-between align-center padding">
			<view class="text-333 flex-sub text-bold">
				团购价格
			</view>
			<view class="flex-treble text-13 flex justify-between align-center">
				<input type="text" v-model="groupPrice" value="" class="text-13 f-grow1" placeholder="请填写团购单价" />
				<view class="color">
					元
				</view>
			</view>

		</view>
		<view class="solid-bottom bg-white text-13 flex justify-between align-center padding">
			<view class="text-333 flex-sub text-bold">
				拼团人数
			</view>
			<view class="flex-treble text-13 flex justify-between align-center">
				<input type="number" v-model="memberCount" value="" class="text-13 f-grow1" placeholder="请填写拼团人数" />
				<view class="color">
					人
				</view>
			</view>

		</view>
		<!-- 	<view class="margin-bottom-sm bg-white text-13 flex justify-between align-center padding">
			<view class="text-333 flex-sub text-bold">
				库存
			</view>
			<input type="text" value="" class="text-13 flex-treble" placeholder="请填写库存数" />
		</view> -->
		<view class="solid-bottom text-13 flex justify-between align-center padding bg-white">
			<view class="text-333 text-bold">
				开始日期
			</view>
			<view class="flex justify-start align-center" @click="openDate(1)">
				<view class="text-767696 margin-right-xs">
					{{startTime}}
				</view>
				<image :src="baseUrl + '/static/right.png'" mode="" style="width: 22rpx;height: 22rpx;"></image>
			</view>
		</view>
		<view class="margin-bottom-sm text-13 flex justify-between align-center padding bg-white">
			<view class="text-333 text-bold">
				结束日期
			</view>
			<view class="flex justify-start align-center" @click="openDate(2)">
				<view class="text-767696 margin-right-xs">
					{{endTime}}
				</view>
				<image :src="baseUrl + '/static/right.png'" mode="" style="width: 22rpx;height: 22rpx;"></image>
			</view>
		</view>
		<!-- <view class="margin-bottom-sm bg-white text-13 flex justify-between align-center padding">
			<view class="text-333 flex-sub text-bold">
				可查看角色
			</view>
			<radio-group class="flex-treble flex justify-around align-center" @change="RadioChange">
				<view class="flex justify-start align-center">
					<radio class="radio yellow" :class="radio=='A'?'bg-white':''" :checked="radio=='A'?true:false"
						value="A"></radio>
					<view class="title text-13 margin-left-xs">全部</view>
				</view>
				<view class="flex justify-start align-center">
					<radio class="radio yellow" :class="radio=='B'?'checked':''" :checked="radio=='B'?true:false"
						value="B"></radio>
					<view class="title text-13 margin-left-xs">角色</view>
				</view>
				<view class="flex justify-start align-center">
					<radio class="radio yellow" :class="radio=='B'?'checked':''" :checked="radio=='B'?true:false"
						value="B"></radio>
					<view class="title text-13 margin-left-xs">角色</view>
				</view>
			</radio-group>
		</view> -->
		<button class="padding bg-color text-white margin radius10 text-15" @click="submit">确定</button>
		<w-picker :visible.sync="visible" mode="date" startYear="2021" endYear="2129" :current="true" fields="hour"
			@confirm="onConfirm($event)" :disabled-after="false" ref="date"></w-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$config.baseUrl,
				imgList: [],
				radio: '',
				startTime: '请选择',
				endTime: '请选择',
				time_type: '',
				groupPrice: '',
				productId: '',
				visible: false,
				isShow: false,
				productInfo: {},
				productId: '',
				id: '',
				shopId: '',
				memberCount: ''
			};
		},
		onLoad(options) {
			console.log(options)
			if (options.item) {
				this.productInfo = JSON.parse(options.item)
				this.productId = JSON.parse(options.item).productId
				this.startTime = JSON.parse(options.item).startTime
				this.endTime = this.productInfo.endTime
				this.groupPrice = this.productInfo.groupPrice / 100
				this.id = this.productInfo.id
				this.shopId = options.id
				this.memberCount = this.productInfo.memberCount


			}
			console.log(this.productInfo)
		},


		methods: {
			RadioChange(e) {
				this.radio = e.detail.value
			},

			openDate(e) {
				this.visible = true
				this.time_type = e

			},
			async submit() {
				const that = this
				const {
					productId,
					startTime,
					endTime,
					groupPrice,
					id,
					shopId,
					memberCount
				} = this
				if (!productId) {
					return this.$util.msg('请选择商品')
				}
				if (!groupPrice) {
					return this.$util.msg('请输入团购价格')
				}
				if (!memberCount) {
					return this.$util.msg('请输入拼团人数')
				} else {
					if (memberCount.length == 1) {
						let regex = /[^2-9]/gi
						if (regex.test(memberCount)) {
							return this.$util.msg('拼团人数格式不符合要求')
						}
					} else {
						let regex = /[\D]/gi
						if (regex.test(memberCount)) {
							return this.$util.msg('拼团人数格式不符合要求')
						}
					}

				}
				if (!startTime) {
					return this.$util.msg('请选择开始时间')
				}
				if (!endTime) {
					return this.$util.msg('请选择结束时间')
				}
				const data = {
					productId,
					groupPrice: groupPrice * 100,
					startTime,
					endTime,
					id,
					shopId,
					memberCount
				}
				const [err, rs] = await this.$jsonPost(this.$api.updateGroup, data)
				if (rs) {
					this.$util.msg(rs.message)
					setTimeout(() => {
						uni.navigateBack({

						})
					}, 1000)

				}

				// uni.showModal({
				//  content: '你确定添加团购商品吗',
				//     success: function (res) {
				//         if (res.confirm) {
				//             console.log('用户点击确定');


				//         } else if (res.cancel) {
				//             console.log('用户点击取消');
				//         }
				//     }
				// });
			},
			onConfirm(e) {
				console.log(e)
				if (this.time_type == 1) {
					this.startTime = e.value
				} else {
					this.endTime = e.value
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cu-form-group {
		margin-top: 74rpx;
		padding: 0;
	}
</style>
